package com.yantong.controller.api;

import com.yantong.controller.BaseController;
import com.yantong.pojo.ShareConfig;
import com.yantong.pojo.TradeConfig;
import com.yantong.result.ResultVo;
import com.yantong.service.ConfigService;
import com.yantong.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: juzi
 * @date: 2021/10/25
 * @time: 16:09
 */
@Controller
@RequestMapping("/wxapi/global")
public class GlobalController extends BaseController {

    @Autowired
    ConfigService configService;

    @Autowired
    MemberService memberService;

    /**
     * 获取平台设置
     */
    @RequestMapping("/config")
    @ResponseBody
    public ResultVo getGlolbalConfig(Long centreId) {
        //商品没有设置提货时间的，使用平台默认设置
        TradeConfig tradeConfig = configService.getTradeConfig(centreId);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", tradeConfig);
        return resultVo;
    }

    /**
     * 全局分享
     *
     * @author kanghaixin
     * @date 2018/9/7.15:39
     */
    @RequestMapping("/share")
    @ResponseBody
    public ResultVo getGlobalShare(Long centerId) {
        ShareConfig shareConfig = configService.getShareConfig(centerId);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", shareConfig);
        resultVo.put("baseData", configService.getBaseConfig(centerId));
        return resultVo;
    }


    /**
     * 根据centerId获得平台的 ShopMemberId (门店id)
     * @param centerId
     * @return
     */
    @RequestMapping("/getShopMemberId")
    @ResponseBody
    public ResultVo getShopMemberIdByCenterId(Long centerId) {
        Long shopMemberId = memberService.getShopMemberIdByCenterId(centerId);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", shopMemberId);
        return resultVo;
    }

    /**
     * 根据shopMemberId 获得 centerId
     * @param shopMemberId
     * @return
     */
    @RequestMapping("/getCenterId")
    @ResponseBody
    public ResultVo getCenterIdByShopMemberId(Long shopMemberId) {
        Long centerId = memberService.getCenterIdByShopMemberId(shopMemberId);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", centerId);
        return resultVo;
    }


}
